package com.tensquare.user.controller;
import entity.Result;
import entity.StatusCode;
import execption.BusinessExecption;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
/**
 * 统一异常处理类
 */
@ControllerAdvice
public class BaseExceptionHandler {
	
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Result error(Exception e){
        e.printStackTrace();
        if(e instanceof BusinessExecption){
            return new Result(false, StatusCode.ERROR, e.getMessage());
        }else if(e instanceof RuntimeException){
            return new Result(false, StatusCode.ERROR, e.getMessage());
        }else{
            return new Result(false, StatusCode.ERROR, "执行出错");
        }
    }
}
